/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.synjones.pay.model.context;

/**
 *
 * @author hsd
 */
public enum StatusInfo {
    _0000("0000", "支付成功"),_0001("0001", "充值成功"),
    _1000("1000", "未支付"), _10001("10001", "该笔订单已支付成功"), _1002("1002", "支付失败"),_1003("1003", "处理中"),
    _2000("2000", "交易类型未授权"), _2001("2001", "应用未授权"),_2002("2002", "商户号未授权"),
    _3000("3000", "暂未开通"),_3001("3001", "暂停服务"),
    _4000("4000", "数据项有误"), _4001("4001", "签名错误"),
    _5000("5000", "平台无此支付类型"), 
    _6000("6000", "系统日期不符"),
    _7000("7000", "用户认证失败"), 
    _9000("9000", "其他错误");

    private final String code;// 状态码
    private final String desc;// 状态码描述

    StatusInfo(String code, String desc) {
        this.code = code;
        this.desc = desc;
    }

    public String code() {
        return code;
    }

    public String desc() {
        return desc;
    }

    /**
     * *
     * 根据code获取描述
     *
     * @param code
     * @return
     */
    public static String getDesc(String code) {

        for (StatusInfo info : StatusInfo.values()) {
            if (code.equals(info.code)) {
                return info.desc;
            }
        }
        return null;
    }

    /**
     * 根据当前code与指定的desc生成CodeDescPair
     *
     * @param defineDesc
     * @return
     */
    public CodeDescPair genStatusInfo(String defineDesc) {
        if (defineDesc != null && !("".equals(defineDesc))) {
            return new CodeDescPair(this.code, defineDesc);
        }
        return new CodeDescPair(this.code, this.desc);
    }

    /**
     * 根据当前的code、desc生成CodeDescPair
     *
     * @return
     */
    public CodeDescPair genStatusInfo() {
        return new CodeDescPair(this.code, this.desc);
    }

    @Override
    public String toString() {
        return this.code + " ：" + this.desc;
    }

    /**
     * 根据数据库中的交易状态字符串生成枚举的交易状态
     *
     * @param status
     * @return
     */
    public static StatusInfo getSIByStr(String status) {
        StatusInfo[] si = StatusInfo.values();
        for (StatusInfo statusInfo : si) {
            if (status.equals(statusInfo.code())) {
                return statusInfo;
            }
        }
        return null;
    }
}
